from datetime import timedelta
from itertools import product

from django.core.management.base import BaseCommand
from django.utils import timezone

from main import models


class Command(BaseCommand):
    def handle(self, *args, **options):
        start = timezone.now()
        times = [start + timedelta(seconds=shift) for shift in range(0, 1000, 20)]
        entities = [models.Entity.objects.get_or_create(name=name)[0] for name in '1234567890']
        data = {}
        models.SimpleTable.objects.bulk_create([
            models.SimpleTable(time=t, entity=entity, data=d)
            for t, entity, d in product(times, entities, [data])
        ])
